package cooperated

import (
	"bytes"
	"fmt"
	"runtime/debug"
	"strings"

	"gddgame.cc/galaxy/common/namespaces/cooperate"
	"gddgame.cc/galaxy/common/namespaces/cooperate/structure"
	"gddgame.cc/galaxy/utils/serialize"
)

func (logic *TypeMap) Move(info *structure.ScheduleInfo, content *cooperate.MoveScheduleContent) {
	slot := serialize.GetSlot()
	switch content.Type {
	case AttackLogicType:
		var attack AttackLogic
		if err := slot.Set(&attack); err != nil {
			fmt.Println("logic move attack", err)
		} else if err := slot.Unmarshal(content.Logic); err != nil {
			fmt.Println("logic move attack", err)
		} else {
			logic.MoveAttack(info, content, &attack)
		}
	}
	slot.Release()
}
func (logic *TypeMap) MoveAttack(info *structure.ScheduleInfo, content *cooperate.MoveScheduleContent, attack *AttackLogic) {
	//start := time.Now()
	index := int(content.Index)
	instance := logic.GetDetailCache(logic, info.Target)
	//result := logic.GetPropsCache(conn, info.MapNoId, info.Target, []string{Position, Identity, Speed, MoveLockTime, AttackDistance, AttackSpeed, Health, Mode, Visible, Combat, Ignore, CrossedTime, BeCrossTime, BeCrossStartTime, CrossedItem, CrossedStartTime, BeCrossItem, Defend})
	if instance == nil {
		fmt.Println("move props miss", info.Target)
		return
	}
	health := instance.ToInt(Health)
	if health <= 0 {
		fmt.Println("move health", info.Target, health)
		return
	}
	selfIdentity := instance.ToInt(Identity)
	speed := instance.AttrWithId(logic.Speed) / 2               // 攻击距离 / 2
	speedChange := instance.AttrWithId(logic.SpeedChange)       // 半格时间
	attackDistance := instance.AttrWithId(logic.AttackDistance) // 攻击距离
	followDistance := instance.AttrWithId(logic.FollowDistance) // 跟随距离

	// 攻击参数获取
	attack.Init(attackDistance, followDistance, content.LastPosition)

	behaviors := logic.bindBehavior(instance, attack.Behaviors, attackDistance)

	moveLock, moveLockTime := instance.Attr(logic.MoveLock)
	targetMode := TargetModeDefine(instance.ToByte(TargetMode))
	visible := TargetVisible(instance.ToInt(Visible))
	combat := instance.ToBool(Combat)
	position := instance.ToBytes(Position)
	//holdBaseTime := utils.ToInt64(result[HoldBaseTime])

	crossedTime := instance.ToInt64(CrossedTime)
	crossedStartTime := instance.ToInt64(CrossedStartTime)
	beCrossItem := instance.ToBytes(BeCrossItem)
	beCrossTime := instance.ToInt64(BeCrossTime)
	beCrossStartTime := instance.ToInt64(BeCrossStartTime)
	crossedItem := instance.ToBytes(CrossedItem)

	plan := content.Plan
	positions := content.Positions
	//fmt.Println("move", info.Target, index, positions, plan, health)

	if strings.Contains(info.Key, ":next") {
		if positions != nil && len(positions) > 0 {
			logic.nextStep(info, positions, index, selfIdentity, visible)
		} else {
			// 可能被销毁，取消next
		}
		return
	}
	needArrive := false
	needPathFinding := false
	needAuto := false
	needContinue := false
	cancelCross := false

	arrive := false
	stop := false
	move := true
	ignore := false
	first := false
	nextArrive := index+2 >= len(positions)
	needAttack := false
	updatePlan := false
	filter := content.Filter
	nextTime := info.Time
	if info.Time < logic.CurrentTime() {
		nextTime = logic.CurrentTime()
	}
	blockTime := int64(0)
	//finishJudge := false

	//var prevPosition []byte
	var nextPosition []byte
	var nnPosition []byte
	var nextPlan []byte

	var nextCrossItem []byte
	var nextCrossTime int64

	//var fixed []byte
	var target *cooperate.TouchTarget
	var crossPath bool
	var end []byte
	var lastPlan bool
	var operateData *cooperate.UpdateOperateData
	//defer func() {
	//	if err := recover(); err != nil {
	//		debug.PrintStack()
	//		fmt.Println("move fail", info.Target, content.Plan, content.Positions, content.Index, content.PlanIndex)
	//	}
	//}()
	//fmt.Println("move", plan, positions, content.PlanIndex, content.Index, lastPlan, arrive)

	operates := []cooperate.UpdateOperateContent{}
	var combatOperates []cooperate.UpdateOperateContent
	var clearOperates []cooperate.UpdateOperateContent

	if index == 0 {
		if content.PlanIndex == 0 {
			content.PlanIndex += 1
			updatePlan = true
			first = true
		}
	}
	if positions == nil || len(positions) == 0 || index >= len(positions) {
		if (content.LastPosition != nil && len(content.LastPosition) > 0) || (content.Touch != nil && content.Touch.Target != nil) {
			// 如果存在目标，朝目标移动
			goto Target
		} else {
			//// 自动
			//needAuto = true
			goto Path
		}
	}

	lastPlan = int(content.PlanIndex)+1 >= len(content.Plan)
	arrive = index+1 == len(positions) && lastPlan
	end = content.Plan[len(content.Plan)-1]
	position = content.Positions[index]
	needContinue = !lastPlan && index+4 >= len(positions)

	if !lastPlan {
		nextPlan = plan[content.PlanIndex+1]
	}
	if index+1 < len(positions) {
		nextPosition = positions[index+1]
	} else {
		nextPosition = nil
	}
	if !nextArrive {
		nnPosition = positions[index+2]
	}

	if beCrossTime >= info.Time && beCrossStartTime <= info.Time {
		crossPath = true
	}

	// 变速计算
	//fmt.Println("speed", info.Target, speed, speedChange, abilityProp.AttrAddition(speed, speedChange))
	speed = instance.AttrAddition(speed, speedChange)

	// 限制移动
	if moveLock > 0 {
		blockTime = int64(moveLockTime) * 1000
		move = false
		goto Send
	}

	//fmt.Println("move", info.BaseData, index, len(content.Positions), content.PlanIndex, len(content.Plan), info.Time)

	//fmt.Println("cross time", info.Target, crossedTime, info.Time, crossedTime > info.Time)
	if crossedTime > info.Time {
		if crossedStartTime > info.Time {
			// 援护还未发生，如果移动，取消援护
			cancelCross = true
		} else {
			blockTime = crossedTime
			move = false
			goto Send
		}
	}

	if !first {
		logic.triggerListen(info.Target, position, info.GetTime())
	}

Target:
	if (content.Status != Auto && content.Status != FinishAuto) || (arrive) {
		// 正常移动，判断攻击
		if len(behaviors) > 0 {
			target = logic.defaultTarget(info.GetMapNoId(), content.Touch, selfIdentity, position, info.Params, info.Time, &behaviors[0])
			if target == nil && attack.CanAttack {
				targets := logic.findTarget(info, attack, position, content.Positions[index:], instance)
				targets = logic.selectTarget(targets, targetMode, selfIdentity, &behaviors[0])
				if len(targets) > 0 {
					target = targets[0]
				}
			}
		}
		if target != nil {
			end = target.Position
			//fmt.Println("move target", info.Target, target.Position, target.Distance, content.LastPosition, info.Time, attack.FollowDistance, attackDistance, positions)
			// 对于攻击目标处理
			if target.Distance <= int(behaviors[0].Distance) {
				goto Attack
			} else if attack.Follow && (attack.FollowDistance == -1 || target.Distance <= int(attack.FollowDistance)) {
				addOperates := logic.addTarget(instance, target)
				if addOperates != nil {
					operates = append(operates, addOperates...)
				}
				// 追击: 目标移动，并且离开终点攻击范围
				if plan == nil || (logic.Distance(plan[len(plan)-1], target.Position) > int(attackDistance)) {
					//fmt.Println("needpatth 1")
					needPathFinding = true
					// 攻击目标走到目标周围，获取目标范围
					// 主动攻击，目标不变，目标移动，直接更换conent内容
					// 自动共攻击，目标随意，目的地不变即可，直接更换conent内容
					content.TargetPositions = logic.getPositions(target)
					goto Path
				} else {
					goto Move
				}
			}
		}
		// 没有目标，但在战斗状态，移除战斗状态
		if combat {
			combatOperates = logic.changeCombat(info, false)
			if combatOperates != nil {
				operates = append(operates, combatOperates...)
			}
		}
		clearOperates = logic.clearTarget(instance)
		if clearOperates != nil {
			operates = append(operates, clearOperates...)
		}
		goto LastEnd
	Attack:
		if crossPath {
			// 在穿过过程，不允许攻击，找寻就近停留点
			needAuto = true
			end = target.Position
			goto Path
		} else {
			content.Status = Normal
			//fmt.Println("switch attack", info.GetTarget(), info.Time)
			// 如果可以停留，则原地停止，进行攻击
			logic.switchAttack(info, content, position, target.Data())
			stop = true
			// 攻击则取消到达，等攻击结束才到达
			arrive = false
			needAttack = true
			goto Send
		}
	}
LastEnd:
	if content.Status != FinishAuto && (content.Status != Auto || (arrive)) {
		// 判断终点
		if content.LastPosition != nil && len(content.LastPosition) > 0 {
			// 返回原地
			if plan == nil || !logic.Equal(plan[len(plan)-1], content.LastPosition) {
				fmt.Println("last not end", info.Target, content.LastPosition, plan[len(plan)-1])
				needPathFinding = true
				arrive = false
				end = content.LastPosition
				goto Path
			}
		} else if crossPath {
			// 在穿过过程，不能直接停留，自动停位
			needAuto = true
			goto Path
		} else if !(arrive) {
			//fmt.Println("move 1")
			arrive = true
			goto Send
		} else {

		}
	}

Move:
	if needContinue {
		goto Path
	}
	// 可移动判断
	if !(arrive) {
		if nextPosition == nil {
			panic("next position is empty")
		}
		//fmt.Println("block", index, len(positions), content.PlanIndex, len(content.Plan))
		var setCrossTime int
		//finishJudge = true
		response := logic.needPathOrBlock(info, content, selfIdentity, position, nextPosition, visible, nextArrive, true, speed)
		if response == nil {
			//fmt.Println("needpatth 2")
			needPathFinding = true
			goto Path
		}

		needArrive = response.NeedArrive
		needPathFinding = response.NeedPathFinding
		blockTime = response.BlockTime
		nextCrossItem = response.CrossItem
		nextCrossTime = response.CrossTime
		// needArrive, needPathFinding, filterPosition, blockTime, nextCrossItem, nextCrossTime, _
		//fmt.Println("block", info.Target, position, nextPosition, needPathFinding, response.FilterPosition, blockTime, nextCrossItem, nextCrossTime, crossPath)
		if blockTime > info.Time && crossPath {
			// 阻挡时间加半格移动时间
			nextCrossTime = blockTime + int64(speed)
			nextCrossItem = crossedItem
			setCrossTime = 0
		} else if needPathFinding && crossPath {
			// 寻路等待时间1000，加100冗余
			nextCrossTime = info.Time + 1100
			nextCrossItem = crossedItem
			setCrossTime = 0
		} else {
			// 半个移动进入时间后开始援护状态
			setCrossTime = speed
		}
		if nextCrossItem != nil && len(nextCrossItem) > 0 {
			// 反向设定穿越
			//fmt.Println("set crossed", info.BaseData, index, info.Time+int64(setCrossTime), nextCrossTime)
			crossItem := structure.NewBaseDataByte(nextCrossItem)
			operateData := []cooperate.OperateData{
				cooperate.NewOperateData(cooperate.BatchUpdateOperate, &cooperate.UpdateOperateData{
					Data: *crossItem,
					Operates: []cooperate.UpdateOperateContent{{
						Operate: cooperate.ChangeData,
						Key:     CrossedTime,
						Value:   nextCrossTime,
					}, {
						Operate: cooperate.ChangeData,
						Key:     CrossedStartTime,
						Value:   info.Time + int64(setCrossTime),
					}, {
						Operate: cooperate.ChangeData,
						Key:     BeCrossItem,
						Value:   info.Target.Bytes(),
					}},
				}),
				cooperate.NewOperateData(cooperate.BatchUpdateOperate, &cooperate.UpdateOperateData{
					Data: *info.Target,
					Operates: []cooperate.UpdateOperateContent{{
						Operate: cooperate.ChangeData,
						Key:     BeCrossTime,
						Value:   nextCrossTime,
					}, {
						Operate: cooperate.ChangeData,
						Key:     BeCrossStartTime,
						Value:   info.Time + int64(setCrossTime),
					}, {
						Operate: cooperate.ChangeData,
						Key:     CrossedItem,
						Value:   nextCrossItem,
					}},
				}),
			}
			logic.scheduleOperate2(info, operateData, 0)
		}
		if needArrive {
			if crossPath {
				//fmt.Println("arrive will auto")
				needAuto = true
				goto Path
			} else {
				//fmt.Println("move 2")
				arrive = true
				goto Send
			}
		}

		if needPathFinding {
			// 存储不可路过的点
			content.Filter = append(content.Filter, nextPosition)
			if len(content.Filter) > 5 {
				content.Filter = content.Filter[len(content.Filter)-5:]
			}
			if response.FilterPosition != nil {
				filter = append(content.Filter, response.FilterPosition)
			} else {
				filter = content.Filter
			}
			if content.Status == Auto || content.Status == FinishAuto {
				needAuto = true
			} else if nextArrive && lastPlan {
				//fmt.Println("arrive error", beCrossTime, crossedTime, crossPath, info.Time)
				// 无法到达，则停止
				// 如果当前点无法停留，则找寻就近停靠点，并锁定
				//
				if crossPath {
					//fmt.Println("arrive will auto")
					needAuto = true
				} else if target == nil {
					//fmt.Println("move 3")
					arrive = true
					goto Send
				}
			}
			//fmt.Println("filter", filter)
			goto Path
		} else if blockTime > info.Time {
			move = false
			goto Send
		} else if cancelCross {
			// 可移动，取消援护
			//fmt.Println("cancel cross", info.BaseData)
			bci := structure.NewBaseDataByte(beCrossItem)
			operateData := []cooperate.OperateData{
				cooperate.NewOperateData(cooperate.BatchUpdateOperate, &cooperate.UpdateOperateData{
					Data: *bci,
					Operates: []cooperate.UpdateOperateContent{{
						Operate: cooperate.ChangeData,
						Key:     BeCrossStartTime,
						Value:   0,
					}, {
						Operate: cooperate.ChangeData,
						Key:     BeCrossTime,
						Value:   0,
					}, {
						Operate: cooperate.ChangeData,
						Key:     CrossedItem,
						Value:   nil,
					}},
				}),
				cooperate.NewOperateData(cooperate.BatchUpdateOperate, &cooperate.UpdateOperateData{
					Data: *info.Target,
					Operates: []cooperate.UpdateOperateContent{{
						Operate: cooperate.ChangeData,
						Key:     CrossedStartTime,
						Value:   0,
					}, {
						Operate: cooperate.ChangeData,
						Key:     CrossedTime,
						Value:   0,
					}, {
						Operate: cooperate.ChangeData,
						Key:     BeCrossItem,
						Value:   nil,
					}},
				}),
			}
			logic.scheduleOperate2(info, operateData, 0)
		}
	}

Path:
	if !needPathFinding && !needAuto {
		if needContinue {
			content.Status = Normal
			if logic.continuePath(position, nextPosition, nextPlan, filter, attack.Pass, info, content, selfIdentity, visible) {
				ignore = true
				goto Send
			}
			// 寻路失败, 重新寻路
			if end != nil && !bytes.Equal(end, nextPlan) {
				needPathFinding = true
			} else if crossPath {
				needAuto = true
			} else {
				//fmt.Println("move 4")
				arrive = true
			}
		}
	}
	if needPathFinding && !needAuto {
		content.Filter = append(content.Filter, position)
		content.Status = Normal
		stop = true
		fmt.Println("move path", info.Target, position, end)
		if end != nil && logic.findPath(position, end, filter, attack.Pass, info, content, selfIdentity, visible) {
			ignore = true
			goto Send
		}
		// 寻路失败
		if crossPath {
			needAuto = true
		} else {
			fmt.Println("move 5")
			arrive = true
		}
	}
	if needAuto {
		if !needAttack && content.LastPosition != nil && len(content.LastPosition) > 0 && logic.Equal(plan[len(plan)-1], content.LastPosition) {
			content.Status = FinishAuto
		} else {
			content.Status = Auto
		}
		stop = true
		if !logic.autoPath(position, end, filter, attack.Pass, info, content, selfIdentity, visible) {
			arrive = true
		}
		goto Send
	}
Send:
	if arrive {
		stop = true
	}
	if stop {
		move = false
	}
	if index == 0 {
		if first {
			operates = append(operates, cooperate.UpdateOperateContent{
				Operate: cooperate.ChangeData,
				Key:     MoveStatus,
				Value:   true,
			})
		}
		if updatePlan {
			//fmt.Println("start move", info.BaseData, positions, plan, info.Time)
			operates = append(operates, cooperate.UpdateOperateContent{
				Operate: cooperate.ChangeData,
				Key:     Plan,
				Value:   plan,
			})
		}
		if !ignore || stop {
			// 如果是短距离，直接会开启下次continue，避免乱序导致positions更新问题，直接取消第一次更新
			// 更新路径信息
			// stop可能是进入攻击，如果不下发， wait会导致坐标错误
			operates = append(operates, cooperate.UpdateOperateContent{
				Operate: cooperate.ChangeData,
				Key:     Positions,
				Value:   positions,
			}, cooperate.UpdateOperateContent{
				Operate: cooperate.ChangeData,
				Key:     PlanIndex,
				Value:   content.PlanIndex,
			})
		}
	}
	if arrive {
		operates = append(operates, cooperate.UpdateOperateContent{
			Operate: cooperate.ChangeData,
			Key:     MoveStatus,
			Value:   false,
		})
	}
	if move {
		breakOperate, _ := logic.breakBehavior(instance, info.Time)
		if breakOperate != nil {
			operates = append(operates, breakOperate...)
		}
	}
	// 发送前进行
	if len(operates) > 0 {
		operateData = &cooperate.UpdateOperateData{
			Data:     *info.Target,
			Operates: operates,
		}
	}

	//if move {
	//fmt.Println("move", info.Target, index, blockTime, "arrive", (arrive), "stop", stop, "path", needPathFinding, "contain", needContinue, "auto", needAuto, "attack", needAttack, content.Status, content.LastPosition, position, nextPosition, crossPath, info.Time, logic.CurrentTime())
	//}

	// continue不需要下发当前，等待后续执行
	if ignore {
		if operateData != nil {
			logic.scheduleBatchUpdateOperate2(info, operateData, 0)
		}
		return
	}

	//fmt.Println("move", info.Target, index, len(content.Positions), content.PlanIndex, len(content.Plan), info.Time, positions, plan)
	extend := cooperate.NewModeExtend([]interface{}{index}, info.MapNoId, nil, position)
	// 移动等待加入持久化
	extend.Persistent = false
	extend.UpdateOperate = operateData

	if stop {
		//fmt.Println("arrive or stop", info.Target, index, len(positions), content.PlanIndex, len(content.Plan), info.Time+50)
		// 到达进行占领逻辑处理
		//logic.moveArriveHold(conn, info, position, selfIdentity)
		// 移动完成发送事件
		e := logic.Event.Wait
		if arrive {
			e = logic.Event.Arrive
		}
		logic.Mode(logic, info.From, info.Target, *e, nextTime+100, extend)

		//logic.setBlock(info.Target, position, nil, nil, nextTime, nextTime, selfIdentity, visible)
		if arrive && positions != nil && len(positions) > 0 {
			// 如果原地没有移动，需要判断positions
			//fmt.Println("move", plan, positions, info.Target, blockTime, "arrive", (arrive), "stop", stop, "path", needPathFinding, "contain", needContinue, "auto", needAuto, "attack", needAttack, content.Status, attack.LastPosition, position, nextPosition, crossPath, info.Time)
			logic.OnEvent(OnArriveEvent, []interface{}{instance, selfIdentity, position, content, info.Time})
		}
		return
	}
	if move {
		logic.Mode(logic, info.From, info.Target, *logic.Event.Move, nextTime+100, extend)

		nextTime += int64(speed)
		content.Index += 1
		arriveTime := nextTime
		stayTime := arriveTime + int64(speed)
		// 如果是目标点，阻拦一半时间, 否则2倍时间
		if !nextArrive {
			stayTime += int64(speed)
		}
		// 设定寻路中状态: can时候已经设定
		logic.setBlock(instance, position, nextPosition, nnPosition, arriveTime, stayTime, selfIdentity, visible)
	} else if blockTime > info.Time {
		logic.Mode(logic, info.From, info.Target, *logic.Event.Wait, nextTime+100, extend)
		//fmt.Println("set Block", info.BaseData)
		// 到达阻挡时间，重新下发移动命令，会再次判断是否存在阻挡
		nextTime = blockTime
		stayTime := blockTime
		// 更新寻路状态

		if position == nil || len(position) == 0 {
			fmt.Println("arrive or stop", info.Target, position)
		}
		logic.setBlock(instance, nil, position, nextPosition, nextTime, stayTime, selfIdentity, visible)
	} else {
		fmt.Println("no move", info.Target, info.Time, index)
		debug.PrintStack()
	}

	//fmt.Println("move", info.Target, speed, nextTime, info.Time, info.Time-logic.CurrentTime())
	if move {
		//fmt.Println("move next", info.Target, info.Key, content.Index)
		// 添加半格坐标确认
		tmp := info.Key
		info.Key = info.Key + ":next"
		info.Depend = tmp
		builder := logic.ScheduleBuilder()
		builder.BindInfo(*info).Move(content).Schedule(nextTime, info.Params, info.ScheduleDelay)
		nextTime += int64(speed)
		info.Key = tmp
		info.Depend = ""
	}

	// 继续执行
	builder := logic.ScheduleBuilder()
	builder.BindInfo(*info).Move(content).Schedule(nextTime, info.Params, info.ScheduleDelay)
}

func (logic *TypeMap) nextStep(info *structure.ScheduleInfo, positions [][]byte, index int, selfIdentity int, visible TargetVisible) bool {
	//defer func() {
	//	if err := recover(); err != nil {
	//		debug.PrintStack()
	//		fmt.Println("next fail", info.Target, positions, index-1, err)
	//	}
	//}()
	prevPosition := positions[index-1]
	nextPosition := positions[index]

	//pl := logic.GetLinksBy(ListenRelation, prevPosition)
	//for _, pp := range pl {
	//	r := structure.NewBaseDataByte(pp)
	//	pp := logic.GetDetailCache(info.MapNoId, r)
	//	// 同势力：当前对象执行执行者事件
	//	event := logic.GetEventCache(info.MapNoId, r, LeaveSystemEvent)
	//	if event != nil {
	//		mapProp := ReceiveMapProp(pp)
	//		flag := true
	//		for _, p := range mapProp.Listen {
	//			if bytes.Equal(nextPosition, p) {
	//				flag = false
	//				break
	//			}
	//		}
	//		if flag {
	//			logic.Mode(info.Target, r, *event, info.Time, cooperate.NewModeExtend([]interface{}{info.Target.DataType, info.Target.Id, LeaveSystemEvent}, info.MapNoId, nil, prevPosition))
	//		}
	//	}
	//}

	operateData := &cooperate.UpdateOperateData{
		Data: *info.Target,
		Operates: []cooperate.UpdateOperateContent{{
			Operate: cooperate.ChangePosition,
			Value:   nextPosition,
		}, {
			Operate: cooperate.ChangeData,
			Key:     Direction,
			Value:   logic.GetDirection(prevPosition, nextPosition),
		}},
	}
	logic.scheduleBatchUpdateOperate2(info, operateData, 0)

	//_, _, fixed := logic.GetNode(nextPosition)
	//if fixed != nil && len(fixed) > 0 {
	//	// 存在建筑则不触发附近监听的攻击
	//	return true
	//}

	//nl := logic.GetLinksBy(ListenRelation, nextPosition)
	////fmt.Println("next", nextPosition, nl)
	//for _, pp := range nl {
	//	r := structure.NewBaseDataByte(pp)
	//	pp := logic.GetDetailCache(info.MapNoId, r)
	//	event := logic.GetEventCache(info.MapNoId, r, EnterSystemEvent)
	//	if event != nil {
	//		mapProp := ReceiveMapProp(pp)
	//		flag := true
	//		for _, p := range mapProp.Listen {
	//			if bytes.Equal(prevPosition, p) {
	//				flag = false
	//				break
	//			}
	//		}
	//		if flag {
	//			logic.Mode(info.Target, r, *event, info.Time, cooperate.NewModeExtend([]interface{}{info.Target.DataType, info.Target.Id, EnterSystemEvent}, info.MapNoId, nil, nextPosition))
	//		}
	//	}
	//}
	return true
}
